From 1c1bb034288af42e5780e88b3475752f70885c5f Mon Sep 17 00:00:00 2001 From: robertl Date: Tue, 1 Aug 2006 15:55:02 +0000 Subject: [PATCH] Add 'heading_true_degrees' to return degrees from 0->360 instead of -180->180. --- gpsbabel/grtcirc.c | 14 ++++++++++++-- gpsbabel/grtcirc.h | 5 ++++- gpsbabel/internal_styles.c | 38 ++++++++++++++++++++++++++++++++++++-- gpsbabel/route.c | 4 ++-- gpsbabel/trackfilter.c | 4 ++-- gpsbabel/wbt-200.c | 4 ++-- 6 files changed, 58 insertions(+), 11 deletions(-) diff --git a/gpsbabel/grtcirc.c b/gpsbabel/grtcirc.c index 18d8db12d..16769e654 100644 --- a/gpsbabel/grtcirc.c +++ b/gpsbabel/grtcirc.c @@ -92,7 +92,9 @@ double gcdist( double lat1, double lon1, double lat2, double lon2 ) return 2.0 * res; } -/* This value is the heading you'd leave point 1 at to arrive at point 2. */ +/* This value is the heading you'd leave point 1 at to arrive at point 2. + * Inputs and outputs are in radians. + */ double heading( double lat1, double lon1, double lat2, double lon2 ) { double v1, v2; v1 = sin(lon1 - lon2) * cos(lat2); @@ -103,7 +105,15 @@ double heading( double lat1, double lon1, double lat2, double lon2 ) { return atan2(v1, v2); } - +/* As above, but outputs is in degrees from 0 - 359. Inputs are still radians. */ +double heading_true_degrees( double lat1, double lon1, double lat2, double lon2 ) +{ + double h = 360.0 - DEG(heading(lat1, lon1, lat2, lon2)); + if (h > 360) h -= 360; + + return h; +} + double linedist(double lat1, double lon1, double lat2, double lon2, diff --git a/gpsbabel/grtcirc.h b/gpsbabel/grtcirc.h index c50ee4591..c47e77dd4 100644 --- a/gpsbabel/grtcirc.h +++ b/gpsbabel/grtcirc.h @@ -24,6 +24,7 @@ double gcdist( double lat1, double lon1, double lat2, double lon2 ); double heading( double lat1, double lon1, double lat2, double lon2 ); +double heading_true_degrees( double lat1, double lon1, double lat2, double lon2 ); double linedist(double lat1, double lon1, double lat2, double lon2, @@ -37,8 +38,10 @@ void linepart(double lat1, double lon1, double frac, double *reslat, double *reslon ); - +/* Degrees to radians */ #define DEG(x) ((x)*180.0/M_PI) + +/* Radians to degrees */ #define RAD(x) ((x)*M_PI/180.0) #endif diff --git a/gpsbabel/internal_styles.c b/gpsbabel/internal_styles.c index 807024c57..e302db82a 100644 --- a/gpsbabel/internal_styles.c +++ b/gpsbabel/internal_styles.c @@ -795,6 +795,40 @@ static char saplus[] = "IFIELD URL, \"\", \"%s\" # URL\n" "IFIELD IGNORE, \"\", \"\" # Holder for Geocache Type\n" +; +static char sportsim[] = +"# gpsbabel XCSV style file\n" +"#\n" +"# Format: Sportsim track files\n" +"# Author: Olaf Klein\n" +"# Date: 07/05/2006\n" +"#\n" +"DESCRIPTION Sportsim track files (part of zipped .ssz files) \n" +"EXTENSION txt\n" + +"#\n" +"# FILE LAYOUT DEFINITIIONS:\n" +"#\n" +"FIELD_DELIMITER SEMICOLON\n" +"RECORD_DELIMITER CRNEWLINE\n" +"BADCHARS TAB\n" + +"#\n" +"# FILE HEADER\n" +"#\n" +"PROLOGUE SportsimVersion:01\n" +"PROLOGUE \\#Sportsim TrackFile\n" + +"#\n" +"# INDIVIDUAL DATA FIELDS:\n" +"#\n" +"IFIELD INDEX, \"\", \"%05d\"\n" +"IFIELD CONSTANT, \"0\", \"%s\"\n" +"IFIELD LAT_DECIMAL, \"\", \"%f\"\n" +"IFIELD LON_DECIMAL, \"\", \"%f\"\n" +"IFIELD ALT_FEET, \"\", \"%.f\"\n" +"IFIELD TIMET_TIME, \"\", \"%ld\"\n" +"IFIELD CONSTANT, \";\", \"%s\"\n" ; static char tabsep[] = "# gpsbabel XCSV style file\n" @@ -958,8 +992,8 @@ static char xmapwpt[] = "IFIELD IGNORE, \"\", \"%-.31s\"\n" "IFIELD DESCRIPTION, \"\", \"%-.78s\"\n" ; -style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap", xmap } , { "xmap2006", xmap2006 } , { "tabsep", tabsep } , { "saplus", saplus } , { "s_and_t", s_and_t } , { "openoffice", openoffice } , { "nima", nima } , { "mxf", mxf } , { "mapconverter", mapconverter } , { "kwf2", kwf2 } , { "ktf2", ktf2 } , { "gpsman", gpsman } , { "gpsdrivetrack", gpsdrivetrack } , { "gpsdrive", gpsdrive } , { "geonet", geonet } , { "garmin_poi", garmin_poi } , { "garmin301", garmin301 } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "cup", cup } , { "csv", csv } , { "cambridge", cambridge } , { "arc", arc } , {0,0}}; -size_t nstyles = 25; +style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap", xmap } , { "xmap2006", xmap2006 } , { "tabsep", tabsep } , { "sportsim", sportsim } , { "saplus", saplus } , { "s_and_t", s_and_t } , { "openoffice", openoffice } , { "nima", nima } , { "mxf", mxf } , { "mapconverter", mapconverter } , { "kwf2", kwf2 } , { "ktf2", ktf2 } , { "gpsman", gpsman } , { "gpsdrivetrack", gpsdrivetrack } , { "gpsdrive", gpsdrive } , { "geonet", geonet } , { "garmin_poi", garmin_poi } , { "garmin301", garmin301 } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "cup", cup } , { "csv", csv } , { "cambridge", cambridge } , { "arc", arc } , {0,0}}; +size_t nstyles = 26; #else /* CSVFMTS_ENABLED */ style_vecs_t style_list[] = {{0,0}}; size_t nstyles = 0; diff --git a/gpsbabel/route.c b/gpsbabel/route.c index d72b0b469..6760c4036 100644 --- a/gpsbabel/route.c +++ b/gpsbabel/route.c @@ -517,8 +517,8 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap) tlon = RAD(this->longitude); plat = RAD(prev->latitude); plon = RAD(prev->longitude); - this->course = DEG(heading(plat, plon, - tlat, tlon)); + this->course = heading_true_degrees(plat, plon, + tlat, tlon); dist = radtometers(gcdist(plat, plon, tlat, tlon)); /* diff --git a/gpsbabel/trackfilter.c b/gpsbabel/trackfilter.c index 84ba3da41..f904db496 100644 --- a/gpsbabel/trackfilter.c +++ b/gpsbabel/trackfilter.c @@ -654,9 +654,9 @@ trackfilter_synth(void) } else { if ( opt_course ) { - wpt->course = DEG(heading( RAD(oldlat), + wpt->course = heading_true_degrees( RAD(oldlat), RAD(oldlon),RAD(wpt->latitude), - RAD(wpt->longitude) )); + RAD(wpt->longitude) ); } if ( opt_speed ) { if ( oldtime != wpt->creation_time ) { diff --git a/gpsbabel/wbt-200.c b/gpsbabel/wbt-200.c index 7922f9230..405506447 100644 --- a/gpsbabel/wbt-200.c +++ b/gpsbabel/wbt-200.c @@ -221,8 +221,8 @@ static void data_chunk(struct read_state *st, const void *buf) { speed = rtm / dtim; wpt->speed = speed; - wpt->course = DEG(heading(RAD(st->plat), RAD(st->plon), - RAD(lat), RAD(lon))); + wpt->course = heading_true_degrees(RAD(st->plat), RAD(st->plon), + RAD(lat), RAD(lon)); wpt->pdop = 0; wpt->fix = fix_unknown; -- 2.30.2